# -*- coding: utf-8 -*-
"""
Created on Fri Mar 31 22:07:23 2017
EulerProject 48
@author: zhiqiang
"""
n = 10
res = 0
for i in range(1,1001):
    mulRes = i
    for j in range(i-1):
        mulRes *= i
        print(mulRes)
        if len(str(mulRes))>n:
            mulRes = int(str(mulRes)[-10:])
            if mulRes==0:
                break
    res += mulRes
    if len(str(res))>n:
        res = int(str(res)[-10:])
print(res)